import Vue from 'vue'
import Router from 'vue-router'
import config from '@/config'

import routes from './constant-routes'

Vue.use(Router)

const router = new Router({
  base: '/vue-template',
  mode: 'history',
  scrollBehavior: () => ({ x: 0, y: 0 }),
  routes
})

router.beforeEach(async(to, from, next) => {
  // 登录未过期或打开页面不需要登录

  return next()
})

router.afterEach(to => {
  // 路由发生变化
  window.document.title = `${config.TITLE}-${to.meta.title}`
})

export default router
